package com.wrupple.muba.widget.client.widgets.toolbar;

import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel.Direction;
import com.google.gwt.user.client.ui.HTML;

public class HorizontalRuler extends Composite implements Toolbar {
	
	private final int size;
	private final Direction direction;
	private final HTML main;
	
	
	
	public HorizontalRuler(int size, Direction direction) {
		super();
		assert direction==Direction.NORTH || direction==Direction.SOUTH;
		this.size = size;
		this.direction = direction;
		main = new HTML();
		initWidget(main);
		DOM.setStyleAttribute(main.getElement(), "fontSize", "80%");
	}

	@Override
	public HandlerRegistration addResizeHandler(ResizeHandler handler) {
		return null;
	}

	@Override
	public Direction getDirection() {
		return direction;
	}

	@Override
	public int getSize() {
		return size;
	}

	protected void addMagnitude(int cellIndex, String magnitude, int cellWidth) {
		Element div = main.getElement();
		Element span = DOM.createSpan();
		span.setInnerText(magnitude);
		span.setClassName("horizontal-span-fixed-width");
		DOM.setStyleAttribute(span, "width", cellWidth+"px");
		div.appendChild(span);
	}
	
	protected void clearRuler() {
		main.setHTML("");
	}
	
}
